window.config = {
	url:"http://127.0.0.1/webserver",
	host:"http://127.0.0.1",
	project:"webapp"
}

function addTab(title,href,icon){
	var tt = $("#tabs");
	if(tt.tabs("exists",title)){
		tt.tabs('select',title);
		refreshTab({tabTitle:title,url:href});
	}else{
		if(href){
			var content = "<iframe scrolling='auto' frameborder='0' src=\'"+href+
			"\' style='width:100%;height:100%;display:block;'></iframe>"
		}else{
			var content = "未实现";
		}
		tt.tabs('add',{
			title:title,
			closable:true,
			content:content,
			iconCls:icon|'icon-default'
		});
		
	}
}
function refreshTab(cfg){
	var refresh_tab = cfg.tabTitle?$("#tabs").tabs('getTab',cfg.tabTitle):$("#tabs").tabs('getSelected');
	if(refresh_tab && refresh_tab.find("iframe").length > 0){
		var _refresh_iframe = refresh_tab.find("iframe")[0];
		var refresh_url  = cfg.url?cfg.url:_refresh_tab.src;
		_refresh_iframe.contentWindow.location.href=refresh_url;
	}
}

function getQueryParameter(paramName){
	var re = new RegExp(paramName+"=([^\&]*)","i");
	var search = document.location.search;
	if(search){
		var res = re.exec(search);
		if(res==null){
			return null;
		}
		return res[1];
	}
	return null;
}

function getFormData(form){
	var data = {};
	var params = $(form).serialize();
	console.log(params);
	params = decodeURI(params);//解决中文编码问题
	var keyvalues = params && params.split("&");
	$(keyvalues).each(function(i,item){
		var key = item.split("=")[0];
		var value = item.split("=")[1];
		if(data[key]){
            var isArray = Array.isArray(data[key]);
            if(isArray){
            	data[key].push(value);
            }else{
            	var tmp = data[key];
				data[key] = [];
				data[key].push(tmp);
				data[key].push(value);
            }
		}else{
			data[key] = value;
		}
	});
	return data;
}

function statusFormatter(val,row){
    if(val=="DISABLE"){
        return "<a class='l-btn-left l-btn-icon-left' style='width:24px;height:24px;'><span class='l-btn-icon icon-no'></span></a>";
    }else{
        return "<a class='l-btn-left l-btn-icon-left' style='width:24px;height:24px;'><span class='l-btn-icon icon-ok'></span></a>";
    }
}

function boolFormatter(val,row){
	if(val==false){
        return "否";
	}else{
		return "是";
	}
}
function typeFormatter(type){
   var res = "";
   switch(type){
     case "SUPERMARKET":
        res = "超市";
        break;
     case "DEPARTMENT_STORE":
        res="百货";
        break;
     case "PRO_SHOP":
        res="家电";
        break;
     default:
        res="超市";
   }
   return res;
}
function marketLevelFormatter(val){
	var res = "";
	switch(val){
		case "1":
			res = "";
			break;
		default:
			res = "";
	}
	return res;
}
function cityLevelFormatter(val){
	var res = "";
	switch(val){
		case "":
			res = "";
			break;
		default:
			res = "";
	}
	return res;
}
function cityScaleFormatter(val){
	var res = "";
	switch(val){
		case "":
			res = "";
			break;
		default:
			res = "";
	}
	return res;
}
function northFormatter(val){
	var res = "";
	switch(val){
		case "":
			res = "";
			break;
		default:
			res = "";
	}
	return res;
}
function areaFormatter(val){
	var res = "";
	switch(val){
		case "":
			res = "";
			break;
		default:
			res = "";
	}
	return res;
}
function btnFormatter(val,row){

}
function changeProperty2String(obj){
	for(var key in obj){
		var tmp = obj[key];
		var type = typeof tmp;
		if("boolean"==type){
			obj[key] = tmp.toString();
		}
	}
	return obj;
}
function transfer(data){
	var result = {};
	for(i in data){
		var tmp = data[i];
		if(tmp){
			result[i] = tmp;
		}
	}
	return result;
}
function load(){
	$("<div class='datagrid-mask'></div>").css({
	  display:'block',
	  width:'100%',
	  height:$(window).height(),
	  zIndex:100
	}).appendTo("body");
	$("<div class='datagrid-mask-msg'></div>").html("正在保存，请稍后...").css({
	  display:'block',
	  left:($(document.body).outerWidth(true)-190)/2,
	  top:($(window).height()-45)/2
	}).appendTo("body");

}
function disLoad(){
	$(".datagrid-mask").remove();
	$(".datagrid-mask-msg").remove();
}

function setNav(){
	var nav = "当前位置：<a class='nav-item'>{{rootMenu}}</a>&gt&gt<a class='nav-item'>{{secondMenu}}</a>";
    var rootMenu = window.parent.window.getRootMenu();
    var secondMenu = window.parent.window.getSecondMenu();
    nav = nav.replace("{{rootMenu}}",rootMenu);
    nav = nav.replace("{{secondMenu}}",secondMenu);
	document.getElementById("nav").innerHTML = nav;
}
